﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.CommonClass;
using HuaCheng.Controller;
using HuaCheng.DataAccess;
using HuaCheng.Model;

namespace HuaCheng.Views
{
    public partial class Dcir : Form
    { 
        //时间编辑控件
        RepositoryItemTimeSpanEdit TimeSpanEdit = new RepositoryItemTimeSpanEdit();
        //自动生成内容的格子
        RepositoryItem TextNoEdit = new RepositoryItemTextEdit();
        //必须编辑的格子
        RepositoryItem TextNeedEdit = new RepositoryItemTextEdit();
        //存储整个DCIR编辑界面的信息
        public StepSetInfo sp;
        //全局参数接收前台传过来的通道信息
        public List<Channel> chlList;
        //并联通道组
        List<int> chlIdList;
        //设备号
        public static string devIp;
        //实际通道号
        int realId;
        //柜号
        int gid;
        //中位机号
        int mid;
        //通道号
        int cid;
        //起始工步号
        public static int startId;
        //判断界面关闭是否由启动按钮触发
        public bool Result;
        //DCIR测试标志
        public static bool dcirFlag = false;
        public Dcir(int realId, string ip, List<int> chlIdList, List<Channel> chls)
        {
            InitializeComponent();
            this.realId = realId;//实际id
            this.mid = chls[realId].Mid;//中位机号
            this.cid = chls[realId].Cid;//映射通道号
            this.gid = chls[realId].Gid;//柜号
            this.chlIdList = chlIdList;//并联列表
            chlList = chls;
            devIp = ip;//设备IP
            reload();
            TimeSpanEdit.AllowEditMilliseconds = true;
            TimeSpanEdit.AllowEditDays = false;
            TextNoEdit.ReadOnly = true;
            TextNeedEdit.KeyPress += CellEdit_KeyPress;
            TextNeedEdit.Leave += CellEdit_Leave;
            TextNeedEdit.Leave += NeedEdit_Leave;
            TimeSpanEdit.Leave += TimeSpan_Leave;
            //如果工步表中不存在该通道的测试记录
            if (StepHelper.GetTestIdById(ip, gid, mid, cid) == "0")
            {
                //loadDoubleCurr();
                loadSingleCurr();
            }
            //如果上次测试不是DCIR测试
            else if (StepHelper.GetDcirFlagById(ip, gid, mid, cid) == false)
            {
                loadSingleCurr();
            }
            //判断是否为DCIR测试
            else if (StepHelper.GetDcirFlagById(ip, gid, mid, cid) == true)
            {
                List<StepInfo> loadStepList = new List<StepInfo>();
                //从表中读取工步数据
                List<byte[]> byteList = StepHelper.GetBinaryListById("0", devIp, gid, mid, cid);
                //将工步数据恢复成StepInfo对象
                for (int i = 0; i < byteList.Count; i++)
                {
                    //将字节数组反序列化StepInfo对象
                    StepInfo stepInfo = (StepInfo)SerializableControl.DeserializeWithBinary(byteList[i]);
                    loadStepList.Add(stepInfo);
                }
                //上一次测试是双电流测试
                if (StepHelper.isDoubleCurr(ip, gid, mid, cid))
                {
                    rbtDouble.Checked = true;
                    tLDcir.ClearNodes();
                    StepControl.SetDoubleByStepInfo(loadStepList, tLDcir);
                }
                //上一次测试是单电流测试
                else
                {
                    rbtSingle.Checked = true;
                    tLDcir.ClearNodes();
                    StepControl.SetSingleByStepInfo(loadStepList, tLDcir);
                }
                //参数设置
                SetProctParameter(loadStepList[0].ProtSelect, loadStepList[0].ProtCondition);
                //创建者
                txtName.Text = loadStepList[0].Creator;
                //电池批号
                txtNo.Text = loadStepList[0].BatteryNum;
                //备注
                txtRemark.Text = loadStepList[0].Remark;
            }
        }
        /// <summary>
        /// 加载双电流DCIR测试
        /// </summary>
        private void loadDoubleCurr()
        {
            if (rbtDouble.Checked == true)
            {
                tLDcir.ClearNodes();
                List<TreeListNode> tLList = new List<TreeListNode>();
                //双电流有6个节点
                for (int i = 0; i < 6; i++)
                {
                    TreeListNode tmpNode = tLDcir.Nodes.Add();
                    tLList.Add(tmpNode);
                    tLDcir.SetRowCellValue(tLList[i], tLDcir.Columns["Index"], i+1);
                    tLDcir.SetRowCellValue(tLList[i], tLDcir.Columns["Variate"], "");
                }
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Property"], "放电电流1");
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Value"], 1.1);
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Unit"], "A");
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Property"], "运行时间1");
                TimeSpan ts = new TimeSpan(0, 0, 0, 30, 0);
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Unit"], "s");
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Property"], "采集时间1");
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Unit"], "s");
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Property"], "放电电流2");
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Value"], 1.1);
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Unit"], "A");
                tLDcir.SetRowCellValue(tLList[4], tLDcir.Columns["Property"], "运行时间2");
                tLDcir.SetRowCellValue(tLList[4], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[4], tLDcir.Columns["Unit"], "s");
                tLDcir.SetRowCellValue(tLList[5], tLDcir.Columns["Property"], "采集时间2");
                tLDcir.SetRowCellValue(tLList[5], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[5], tLDcir.Columns["Unit"], "s");
            }
        }
        /// <summary>
        /// 加载单电流DCIR
        /// </summary>
        private void loadSingleCurr()
        {
            if (rbtSingle.Checked == true)
            {
                tLDcir.ClearNodes();
                List<TreeListNode> tLList = new List<TreeListNode>();
                //单电流有4个节点
                for (int i = 0; i < 4; i++)
                {
                    TreeListNode tmpNode = tLDcir.Nodes.Add();
                    tLList.Add(tmpNode);
                    tLDcir.SetRowCellValue(tLList[i], tLDcir.Columns["Index"], i + 1);
                    tLDcir.SetRowCellValue(tLList[i], tLDcir.Columns["Variate"], "");
                }
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Property"], "放电电流1");
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Value"], 1.1);
                tLDcir.SetRowCellValue(tLList[0], tLDcir.Columns["Unit"], "A");
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Property"], "运行时间1");
                TimeSpan ts = new TimeSpan(0, 0, 0, 30, 0);
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[1], tLDcir.Columns["Unit"], "s");
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Property"], "采集时间1");
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[2], tLDcir.Columns["Unit"], "s");
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Property"], "采集时间2");
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Value"], ts);
                tLDcir.SetRowCellValue(tLList[3], tLDcir.Columns["Unit"], "s");
            }
        }
        /// <summary>
        /// 单元格获取焦点时触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLDcir_CustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e)
        {
            //双电流
            if (tLDcir.Nodes.Count == 6)
            {
                string str_index = Convert.ToString(e.Node["Index"]);
                switch (str_index)
                {
                    //设置2、3、5、6行（时间对应行）的单元格属性
                    case "2":
                    case "3":
                    case "5":
                    case "6":
                        {
                            switch (e.Column.Name)
                            {
                                //时间行的设置值这一列为TimeSpanEdit
                                case "tLValue":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    }
                                    break;
                                //其他列不可编辑
                                default:
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    }
                                    break;
                            }
                        }
                        break;
                    //除时间行外的
                    case "1":
                    case "4":
                        {
                            switch (e.Column.Name)
                            {
                                //设置为必须编辑
                                case "tLValue":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    }
                                    break;
                                //其他列不可编辑
                                default:
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }
            //单电流
            else if(tLDcir.Nodes.Count==4)
            {
                string str_index = Convert.ToString(e.Node["Index"]);
                switch (str_index)
                {
                    //设置2、3、4行（时间对应行）的单元格属性
                    case "2":
                    case "3":
                    case "4":
                        {
                            switch (e.Column.Name)
                            {
                                //时间行的设置值这一列为TimeSpanEdit
                                case "tLValue":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    }
                                    break;
                                //其他列不可编辑
                                default:
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    }
                                    break;
                            }
                        }
                        break;
                    //除时间行外的
                    case "1":
                        {
                            switch (e.Column.Name)
                            {
                                //设置为必须编辑
                                case "tLValue":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    }
                                    break;
                                //其他列不可编辑
                                default:
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }
        }
        /// <summary>
        /// 选择单电流
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rbtSingle_CheckedChanged(object sender, EventArgs e)
        {
            loadSingleCurr();
            ClearParameter();
        }
        /// <summary>
        /// 选择双电流
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rbtDouble_CheckedChanged(object sender, EventArgs e)
        {
            loadDoubleCurr();
            ClearParameter();
        }
        private void reload()
        {
            UserLogin.success = true;
            if (UserLogin.success)
            {
                List<string> currentCode = AuthorityControl.GetAuthority("admin");
                if (currentCode != null)
                {
                    if (currentCode.Contains("24"))
                    {
                        tLDcir.Enabled = true;
                    }
                    if (currentCode.Contains("14"))
                    {
                        SetFuncState(true);
                    }
                }
            }
        }
        /// <summary>
        /// 设置DCIR保护条件权限
        /// </summary>
        /// <param name="flag"></param>
        private void SetFuncState(bool flag)
        {
            gbxRecordCondition.Enabled = flag;
            gbxDelayProct.Enabled = flag;
            gbxHuaChengProct.Enabled = flag;
            gbxSafeProtection.Enabled = flag;
            gbxPlatformV.Enabled = flag;
            gbxCustomerCurr.Enabled = flag;
            chkActivitiesCP.Enabled = flag;
            gbxBase.Enabled = flag;
        }
        private StepInfo GetProctParameter()
        {
            StepInfo stepInfo = new StepInfo();
            ProtectSelect protSel = new ProtectSelect();
            ProtectCondition protCon = new ProtectCondition();
            //时间间隔
            if (chkTimeSpanRC.Checked == true)
            {
                protSel.SelTimeSpan = true;
                protCon.TimeSpan = txtTimeSpanRC.Text;
            }
            else
            {
                protSel.SelTimeSpan = false;
                protCon.TimeSpan = "0";
            }
            //电压间隔
            if (chkVSpanRC.Checked == true)
            {
                protSel.SelVolSpan = true;
                protCon.VoltageSpan = txtVSpanRC.Text;
            }
            else
            {
                protSel.SelVolSpan = false;
                protCon.VoltageSpan = "0";
            }
            //电流间隔
            if (chkASpanRC.Checked == true)
            {
                protSel.SelCurrSpan = true;
                protCon.CurrentSpan = txtASpanRC.Text;
            }
            else
            {
                protSel.SelCurrSpan = false;
                protCon.CurrentSpan = "0";
            }
            //工步延时
            if (chkStepDelayDP.Checked == true)
            {
                protSel.SelStepDelay = true;
                protCon.StepDelay = txtStepDelayDP.Text;
            }
            else
            {
                protSel.SelStepDelay = false;
                protCon.StepDelay = "0";
            }
            //接续延时
            if (chkConDelayDP.Checked == true)
            {
                protSel.SelConDelay = true;
                protCon.ContinueDelay = txtConDelayDP.Text;
            }
            else
            {
                protSel.SelConDelay = false;
                protCon.ContinueDelay = "0";
            }
            //化成保护条件
            if (chkVChangeRateHCP.Checked == true)
            {
                protSel.SelVolRate = true;
                protCon.DetectionTime = txtDetectionTimeHCP.Text;
                protCon.VoltageValue = txtVValueHCP.Text;
            }
            else
            {
                protSel.SelVolRate = false;
                protCon.DetectionTime = "0";
                protCon.VoltageValue = "0";
            }
            //电压下限
            if (chkVMinSP.Checked == true)
            {
                protSel.SelVolMin = true;
                protCon.VoltageMin = txtVMinSP.Text;
            }
            else
            {
                protSel.SelVolMin = false;
                protCon.VoltageMin = "0";
            }
            //电压上限
            if (chkVMaxSP.Checked == true)
            {
                protSel.SelVolMax = true;
                protCon.VoltageMax = txtVMaxSP.Text;
            }
            else
            {
                protSel.SelVolMax = false;
                protCon.VoltageMax = "0";
            }
            //电流下限
            if (chkAMinSP.Checked == true)
            {
                protSel.SelCurrMin = true;
                protCon.CurrentMin = txtAMinSP.Text;
            }
            else
            {
                protSel.SelCurrMin = false;
                protCon.CurrentMin = "0";
            }
            //电流上限
            if (chkAMaxSP.Checked == true)
            {
                protSel.SelCurrMax = true;
                protCon.CurrentMax = txtAMaxSP.Text;
            }
            else
            {
                protSel.SelCurrMax = false;
                protCon.CurrentMax = "0";
            }
            //温度上限
            if (chkTMaxSP.Checked == true)
            {
                protSel.SelTempeMax = true;
                protCon.TemperatureMax = txtTMaxSP.Text;
            }
            else
            {
                protSel.SelTempeMax = false;
                protCon.TemperatureMax = "0";
            }
            //平台电压1
            if (chkPlatform1PV.Checked == true)
            {
                protSel.SelPlatform1 = true;
                protCon.Platform1 = txtPlatform1PV.Text;
            }
            else
            {
                protSel.SelPlatform1 = false;
                protCon.Platform1 = "0";
            }
            //平台电压2
            if (chkPlatform2PV.Checked == true)
            {
                protSel.SelPlatform2 = true;
                protCon.Platform2 = txtPlatform2PV.Text;
            }
            else
            {
                protSel.SelPlatform2 = false;
                protCon.Platform2 = "0";
            }
            //平台电压3
            if (chkPlatform3PV.Checked == true)
            {
                protSel.SelPlatform3 = true;
                protCon.Platform3 = txtPlatform3PV.Text;
            }
            else
            {
                protSel.SelPlatform3 = false;
                protCon.Platform3 = "0";
            }
            //客户电流上下限
            if (chkCustCurr.Checked == true)
            {
                protSel.SelCustCurr = true;
                protCon.CustomerCurrMin = txtCustomerCurrMin.Text;
                protCon.CustomerCurrMax = txtCustomerCurrMax.Text;
            }
            else
            {
                protSel.SelCustCurr = false;
                protCon.CustomerCurrMin = "0";
                protCon.CustomerCurrMax = "0";
            }
            //活性物质
            if (chkActivitiesCP.Checked == true)
            {
                protSel.SelActivities = true;
                protCon.Activities = txtActivitiesCP.Text;
            }
            else
            {
                protSel.SelActivities = false;
                protCon.Activities = "0";
            }
            stepInfo.ProtSelect = protSel;
            stepInfo.ProtCondition = protCon;
            return stepInfo;
        }
        /// <summary>
        /// 除化成电压变化率和活性物质勾选框外的勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkParameterSet_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkParameter = sender as CheckBox;
            string chkParaName = chkParameter.Name;
            string tbParaName = "txt" + chkParaName.Substring(3);
            GroupBox gbParameter = (GroupBox)chkParameter.Parent;
            //通过勾选框找到其对应的文本框
            TextBox tbParameter = (TextBox)gbParameter.Controls[tbParaName];
            if (chkParameter.Checked == true)
            {
                tbParameter.Enabled = true;
                tbParameter.Focus();
            }
            else
            {
                tbParameter.Enabled = false;
            }
        }
        /// <summary>
        /// 化成电压变化率勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkVChangeRateHCP_CheckedChanged(object sender, EventArgs e)
        {
            if (chkVChangeRateHCP.Checked == true)
            {
                txtDetectionTimeHCP.Enabled = true;
                txtVValueHCP.Enabled = true;
            }
            else
            {
                txtDetectionTimeHCP.Enabled = false;
                txtVValueHCP.Enabled = false;
            }
        }
        /// <summary>
        /// 活性物质勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkActivitiesCP_CheckedChanged(object sender, EventArgs e)
        {
            if (chkActivitiesCP.Checked == true)
            {
                txtActivitiesCP.Enabled = true;
                txtActivitiesCP.Focus();
            }
            else
            {
                txtActivitiesCP.Enabled = false;
            }
        }
        /// <summary>
        /// 客户电流上下限勾选框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkCustCurr_CheckedChanged(object sender, EventArgs e)
        {
            if (chkCustCurr.Checked == true)
            {
                txtCustomerCurrMin.Enabled = true;
                txtCustomerCurrMax.Enabled = true;
            }
            else
            {
                txtCustomerCurrMin.Enabled = false;
                txtCustomerCurrMax.Enabled = false;
            }
        }
         /// <summary>
        /// 保护条件值的显示
        /// </summary>
        /// <param name="txtNameValue"></param>
        private void SetProctParameter(ProtectSelect protSel, ProtectCondition protCon)
        {
            if (protSel != null)
            {
                //时间间隔
                if (protSel.SelTimeSpan == true)
                {
                    chkTimeSpanRC.Checked = true;
                    txtTimeSpanRC.Text = protCon.TimeSpan;
                }
                else
                {
                    chkTimeSpanRC.Checked = false;
                    txtTimeSpanRC.Text = "";
                }
                //电压间隔
                if (protSel.SelVolSpan == true)
                {
                    chkVSpanRC.Checked = true;
                    txtVSpanRC.Text = protCon.VoltageSpan;
                }
                else
                {
                    chkVSpanRC.Checked = false;
                    txtVSpanRC.Text = "";
                }
                //电流间隔
                if (protSel.SelCurrSpan == true)
                {
                    chkASpanRC.Checked = true;
                    txtASpanRC.Text = protCon.CurrentSpan;
                }
                else
                {
                    chkASpanRC.Checked = false;
                    txtASpanRC.Text = "";
                }
                //工步延时
                if (protSel.SelStepDelay == true)
                {
                    chkStepDelayDP.Checked = true;
                    txtStepDelayDP.Text = protCon.StepDelay;
                }
                else
                {
                    chkStepDelayDP.Checked = false;
                    txtStepDelayDP.Text = "";
                }
                //接续延时
                if (protSel.SelConDelay == true)
                {
                    chkConDelayDP.Checked = true;
                    txtConDelayDP.Text = protCon.ContinueDelay;
                }
                else
                {
                    chkConDelayDP.Checked = false;
                    txtConDelayDP.Text = "";
                }
                //化成保护条件
                if (protSel.SelVolRate == true)
                {
                    chkVChangeRateHCP.Checked = true;
                    txtDetectionTimeHCP.Text = protCon.DetectionTime;
                    txtVValueHCP.Text = protCon.VoltageValue;
                }
                else
                {
                    chkVChangeRateHCP.Checked = false;
                    txtDetectionTimeHCP.Text = "";
                    txtVValueHCP.Text = "";
                }
                //电压下限
                if (protSel.SelVolMin == true)
                {
                    chkVMinSP.Checked = true;
                    txtVMinSP.Text = protCon.VoltageMin;
                }
                else
                {
                    chkVMinSP.Checked = false;
                    txtVMinSP.Text = "";
                }
                //电压上限
                if (protSel.SelVolMax == true)
                {
                    chkVMaxSP.Checked = true;
                    txtVMaxSP.Text = protCon.VoltageMax;
                }
                else
                {
                    chkVMaxSP.Checked = false;
                    txtVMaxSP.Text = "";
                }
                //电流下限
                if (protSel.SelCurrMin == true)
                {
                    chkAMinSP.Checked = true;
                    txtAMinSP.Text = protCon.CurrentMin;
                }
                else
                {
                    chkAMinSP.Checked = false;
                    txtAMinSP.Text = "";
                }
                //电流上限
                if (protSel.SelCurrMax == true)
                {
                    chkAMaxSP.Checked = true;
                    txtAMaxSP.Text = protCon.CurrentMax;
                }
                else
                {
                    chkAMaxSP.Checked = false;
                    txtAMaxSP.Text = "";
                }
                //温度上限
                if (protSel.SelTempeMax == true)
                {
                    chkTMaxSP.Checked = true;
                    txtTMaxSP.Text = protCon.TemperatureMax;
                }
                else
                {
                    chkTMaxSP.Checked = false;
                    txtTMaxSP.Text = "";
                }
                //平台电压1
                if (protSel.SelPlatform1 == true)
                {
                    chkPlatform1PV.Checked = true;
                    txtPlatform1PV.Text = protCon.Platform1;
                }
                else
                {
                    chkPlatform1PV.Checked = false;
                    txtPlatform1PV.Text = "";
                }
                //平台电压2
                if (protSel.SelPlatform2 == true)
                {
                    chkPlatform2PV.Checked = true;
                    txtPlatform2PV.Text = protCon.Platform2;
                }
                else
                {
                    chkPlatform2PV.Checked = false;
                    txtPlatform2PV.Text = "";
                }
                //平台电压3
                if (protSel.SelPlatform3 == true)
                {
                    chkPlatform3PV.Checked = true;
                    txtPlatform3PV.Text = protCon.Platform3;
                }
                else
                {
                    chkPlatform3PV.Checked = false;
                    txtPlatform3PV.Text = "";
                }
                //客户电流上下限
                if (protSel.SelCustCurr == true)
                {
                    chkCustCurr.Checked = true;
                    txtCustomerCurrMin.Text = protCon.CustomerCurrMin;
                    txtCustomerCurrMax.Text = protCon.CustomerCurrMax;
                }
                else
                {
                    chkCustCurr.Checked = false;
                    txtCustomerCurrMin.Text = "";
                    txtCustomerCurrMax.Text = "";
                }
                //活性物质
                if (protSel.SelActivities == true)
                {
                    chkActivitiesCP.Checked = true;
                    txtActivitiesCP.Text = protCon.Activities;
                }
                else
                {
                    chkActivitiesCP.Checked = false;
                    txtActivitiesCP.Text = "";
                }
            }
        }
        /// <summary>
        /// 清除标准工步参数设置
        /// </summary>
        private void ClearParameter()
        {
            foreach (Control gbControl in this.Controls)
            {
                if (gbControl is GroupBox)
                {
                    //化成保护条件groupbox
                    if (gbControl.Name == "gbxHuaChengProct")
                    {
                        chkVChangeRateHCP.Checked = false;
                        txtDetectionTimeHCP.Text = "";
                        txtVValueHCP.Text = "";
                    }
                    //客户电流上下限groupbox
                    else if (gbControl.Name == "gbxCustomerCurr")
                    {
                        chkCustCurr.Checked = false;
                        txtCustomerCurrMin.Text = "";
                        txtCustomerCurrMax.Text = "";
                    }
                    else
                    {
                        //遍历除化成保护条件之外的groupbox中的checkbox
                        foreach (Control chkControl in gbControl.Controls)
                        {
                            if (chkControl is CheckBox)
                            {
                                CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                chkIndividual.Checked = false;
                                txtIndividual.Text = "";
                            }
                        }
                    }
                }
            }
            //活性物质
            chkActivitiesCP.Checked = false;
            txtActivitiesCP.Text = "";
        }
        /// <summary>
        /// 取消按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 将数据打包给StepInfo
        /// </summary>
        /// <returns></returns>
        private List<StepInfo> PackageStepInfo()
        {
            List<StepInfo> stepList = new List<StepInfo>();
            //双电流
            if (rbtDouble.Checked == true)
            {
                stepList = StepControl.GetDoubleCurrBytreeList(tLDcir);
            }
            else if (rbtSingle.Checked == true)
            {
                stepList = StepControl.GetSingleCurrBytreeList(tLDcir);
            }
            //起始工步
            stepList[0].StartStep = 1;
            //创建者
            stepList[0].Creator = txtName.Text;
            //电池批号
            stepList[0].BatteryNum = (txtNo.Text == "") ? System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : txtNo.Text;
            //备注
            stepList[0].Remark = txtRemark.Text;
            return stepList;
        }
        /// <summary>
        /// 确定按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (tLDcir.Nodes.Count > 0)
            {
                //保护条件
                StepInfo stepInfo = GetProctParameter();
                if (rbtDouble.Checked == true)
                {
                    if (tLDcir.Nodes.Count > 3)
                    {
                        tLDcir.Nodes[3]["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                        tLDcir.Nodes[3]["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                    }
                }
                tLDcir.Nodes[0]["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                tLDcir.Nodes[0]["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                List<StepInfo> customList = new List<StepInfo>();
                customList = PackageStepInfo();//把数据打包
                sp = new StepSetInfo();
                sp.StepList = customList;
                sp.RealId = realId;
                sp.Gid = gid;
                sp.Mid = mid;
                sp.Cid = cid;
                sp.DevIp = devIp;
                sp.ParallelList = chlIdList;
                sp.ChlList = chlList;
                sp.StartStep = 1;
                dcirFlag = true;
                sp.isDcir = dcirFlag;
                if (chlIdList.Count > 0)
                {
                    StepSet.SaveTestInfo(chlList[realId], customList[0], "0", 1);//保存到测试表
                }
                else
                {
                    StepSet.SaveTestInfo(chlList[realId], customList[0], "0", 0);//保存到测试表
                }
                sp.TestId = TestHelper.GetTestId(devIp, gid, mid, cid);//从test表中获取测试号
                string testId = TestHelper.GetTestId(chlList[realId].DevIp, chlList[realId].Gid, chlList[realId].Mid, chlList[realId].Cid);//重新获取测试表测试id
                StepSet.SaveStepInfo(customList, chlList[realId], testId);//保存到工步表
                Result = true;
                CheckLogControl.WriteToDeviceLog("tsmiDcir", gid, mid, cid);//写入设备日志
            }
            this.Close();
        }
        #region 保护条件输入数值验证
        /// <summary>
        /// 保护条件中的电压下限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtVMinSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string volUp = DicHelper.RetrieveVolUpper();
                string volDown = DicHelper.RetrieveVolLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Volt") < Convert.ToSingle(volDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") >= Convert.ToSingle(volUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件的电压上限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtVMaxSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string volUp = DicHelper.RetrieveVolUpper();
                string volDown = DicHelper.RetrieveVolLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Volt") <= Convert.ToSingle(volDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") > Convert.ToSingle(volUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件中的电流下限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtAMinSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string currUp = DicHelper.RetrieveCurrUpper();
                string currDown = DicHelper.RetrieveCurrLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Curr") < Convert.ToSingle(currDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") >= Convert.ToSingle(currUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件中的电流上限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtAMaxSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string currUp = DicHelper.RetrieveCurrUpper();
                string currDown = DicHelper.RetrieveCurrLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Curr") <= Convert.ToSingle(currDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") > Convert.ToSingle(currUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// V和A输入数值校验（整数和小数点后最多4位小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键和负号  
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
            {
                e.Handled = true;
            }
            if (e.KeyChar == (char)('-'))
            {
                if (((TextBox)sender).Text != "")
                {
                    e.Handled = true;
                }
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //第一位是负号，第二位不能为小数点
            if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
            {
                e.Handled = true;
            }
            //第一位是-，第二位是0时，第三位为小数点或者退格
            if (((TextBox)sender).Text == "-0" && e.KeyChar != (char)('.') && e.KeyChar != 8)
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 4 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 时间、温度验证（正整数、正小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTime_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 4 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 时间间隔验证（毫秒必须是10的倍数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTimeSpanRC_Leave(object sender, EventArgs e)
        {
            if (((TextBox)sender).Text == "")
            {
                string chkName = "chk" + ((TextBox)sender).Name.Substring(3);
                CheckBox chkSetState = (CheckBox)((TextBox)sender).Parent.Controls[chkName];
                ((TextBox)sender).Text = "0";
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show(chkSetState.Text + " empty");
                }
                else
                {
                    MessageBox.Show(chkSetState.Text + "不能为空");
                }
            }
            if (lblTimeUnit1.Text == "msec")
            {
                if (!Convert.ToString(((TextBox)sender).Text).EndsWith("0"))
                {
                    ((TextBox)sender).Text = "";
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("Time span should be a multiple of 10!");
                    }
                    else
                    {
                        MessageBox.Show("时间间隔应为10的倍数！");
                    }
                }
            }
            if (Convert.ToString(((TextBox)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextBox)sender).Text, @"0").Count + Regex.Matches(((TextBox)sender).Text, @"\.").Count != ((TextBox)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextBox)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextBox)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "0");
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "");
                        }
                    }
                }
                else
                {
                    ((TextBox)sender).Text = "0";
                }
            }
        }
        /// <summary>
        /// 时间间隔验证（秒最多2位小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTimeSpanRC_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多2位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 2 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 去掉数值前面0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtNumber_Leave(object sender, EventArgs e)
        {
            if (Convert.ToString(((TextBox)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextBox)sender).Text, @"0").Count + Regex.Matches(((TextBox)sender).Text, @"\.").Count != ((TextBox)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextBox)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextBox)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "0");
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "");
                        }
                    }
                }
                else
                {
                    ((TextBox)sender).Text = "0";
                }
            }
            TextBox tBox = sender as TextBox;
            switch (tBox.Name)
            {
                case "txtVMinSP":
                case "txtVMaxSP":
                    {
                        JudgeUpAndDown(txtVMaxSP.Text, txtVMinSP.Text, chkVMaxSP.Checked, chkVMinSP.Checked, tBox, "电压上限必须大于电压下限");
                    } break;
                case "txtAMinSP":
                case "txtAMaxSP":
                    {
                        JudgeUpAndDown(txtAMaxSP.Text, txtAMinSP.Text, chkAMaxSP.Checked, chkAMinSP.Checked, tBox, "电流上限必须大于电流下限");
                    } break;
                case "txtCustomerCurrMin":
                case "txtCustomerCurrMax":
                    {
                        JudgeUpAndDown(txtCustomerCurrMax.Text, txtCustomerCurrMin.Text, chkCustCurr.Checked, chkCustCurr.Checked, tBox, "客户电流上限必须大于客户电流下限");
                    } break;
            }
        }
        /// <summary>
        /// 判断上限是否大于下限
        /// </summary>
        /// <param name="txtUp"></param>
        /// <param name="txtDown"></param>
        /// <param name="chkUp"></param>
        /// <param name="chkDown"></param>
        /// <param name="tBox"></param>
        /// <param name="msg"></param>
        private void JudgeUpAndDown(string txtUp, string txtDown, bool chkUp, bool chkDown, TextBox tBox, string msg)
        {
            if (chkUp && chkDown && txtUp != "" && txtDown != "")
            {
                if (Convert.ToSingle(txtDown) >= Convert.ToSingle(txtUp))
                {
                    MessageBox.Show(msg);
                    tBox.Text = "";
                    tBox.Focus();
                }
            }
        }
        /// <summary>
        /// 校验保护条件中是否有打勾却为空的情况
        /// </summary>
        /// <param name="isConditionOk"></param>
        /// <returns></returns>
        private bool ValidateNullProct(bool isConditionOk)
        {
            foreach (Control gbControl in this.Controls)
            {
                if (gbControl is GroupBox)
                {
                    //化成保护条件groupbox
                    if (gbControl.Name == "gbxHuaChengProct")
                    {
                        if (chkVChangeRateHCP.Checked == true)
                        {
                            if (txtDetectionTimeHCP.Text == "" || txtVValueHCP.Text == "")
                            {
                                isConditionOk = false;
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Selected protect condition empty");
                                }
                                else
                                {
                                    MessageBox.Show("已经选中的保护条件不能为空");
                                }
                                break;
                            }
                        }
                    }
                    //客户电流上下限groupbox
                    else if (gbControl.Name == "gbxCustomerCurr")
                    {
                        if (chkCustCurr.Checked == true)
                        {
                            if (txtCustomerCurrMin.Text == "" || txtCustomerCurrMax.Text == "")
                            {
                                isConditionOk = false;
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Selected protect condition empty");
                                }
                                else
                                {
                                    MessageBox.Show("已经选中的保护条件不能为空");
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        //遍历除化成保护条件和客户电流上下限之外的groupbox中的checkbox
                        foreach (Control chkControl in gbControl.Controls)
                        {
                            if (chkControl is CheckBox)
                            {
                                CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                //若打钩，则将对应的文本框的值存入字典txtNameValue
                                if (chkIndividual.Checked == true)
                                {
                                    if (txtIndividual.Text == "")
                                    {
                                        isConditionOk = false;
                                        if (IndexPage.language == "en-US")
                                        {
                                            MessageBox.Show("Selected protect condition empty");
                                        }
                                        else
                                        {
                                            MessageBox.Show("已经选中的保护条件不能为空");
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //活性物质
            if (chkActivitiesCP.Checked == true)
            {
                if (txtActivitiesCP.Text == "")
                {
                    isConditionOk = false;
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("Selected protect condition empty");
                    }
                    else
                    {
                        MessageBox.Show("已经选中的保护条件不能为空");
                    }
                }
            }
            return isConditionOk;
        }
        #endregion
        #region 工步校验
        /// <summary>
        /// 设置单元格中只允许输入数字，‘.’，退格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CellEdit_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((DevExpress.XtraEditors.TextEdit)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((DevExpress.XtraEditors.TextEdit)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((DevExpress.XtraEditors.TextEdit)sender).SelectionStart) > (((DevExpress.XtraEditors.TextEdit)sender).Text.LastIndexOf('.')) + 4 && ((DevExpress.XtraEditors.TextEdit)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 去掉数字前面的0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CellEdit_Leave(object sender, EventArgs e)
        {
            if (Convert.ToString(((TextEdit)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextEdit)sender).Text, @"0").Count + Regex.Matches(((TextEdit)sender).Text, @"\.").Count != ((TextEdit)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextEdit)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextEdit)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            tLDcir.SetFocusedValue(reg.Replace(((TextEdit)sender).Text, "0"));
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            tLDcir.SetFocusedValue(reg.Replace(((TextEdit)sender).Text, ""));
                        }
                    }
                }
                else
                {
                    tLDcir.SetFocusedValue("0");
                }
            }
        }
        /// <summary>
        /// 必填单元格失去焦点时，判断是否为空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NeedEdit_Leave(object sender, EventArgs e)
        {
            //为空校验
            if (Convert.ToString(tLDcir.FocusedValue).Length == 0 || (Convert.ToString(tLDcir.FocusedValue).Length == 1 && Convert.ToString(tLDcir.FocusedValue) == "."))
            {
                if (rbtDouble.Checked == true)
                {
                    //根据序号来决定为空时的提示文本
                    switch (Convert.ToString(tLDcir.FocusedNode["Index"]))
                    {
                        case "4":
                            {
                                if (tLDcir.FocusedColumn.FieldName == "Value")
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("放电电流2 empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("放电电流2不能为空");
                                    }
                                }
                            } break;
                        case "5":
                            {
                                if (tLDcir.FocusedColumn.FieldName == "Value")
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("运行时间2 empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("运行时间2不能为空");
                                    }
                                }
                            } break;
                        case "6":
                            {
                                if (tLDcir.FocusedColumn.FieldName == "Value")
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("采集时间2 empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("采集时间2不能为空");
                                    }
                                }
                            } break;
                    }
                }
                else if (rbtSingle.Checked == true)
                {
                    switch (Convert.ToString(tLDcir.FocusedNode["Index"]))
                    {
                        case "4":
                            {
                                if (tLDcir.FocusedColumn.FieldName == "Value")
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("采集时间2 empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("采集时间2不能为空");
                                    }
                                }
                            } break;
                    }
                }
                //根据序号来决定为空时的提示文本
                switch (Convert.ToString(tLDcir.FocusedNode["Index"]))
                {
                    case "1":
                        {
                            if (tLDcir.FocusedColumn.FieldName == "Value")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("放电电流1 empty");
                                }
                                else
                                {
                                    MessageBox.Show("放电电流1不能为空");
                                }
                            }
                        } break;
                    case "2":
                        {
                            if (tLDcir.FocusedColumn.FieldName == "Value")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("运行时间1 empty");
                                }
                                else
                                {
                                    MessageBox.Show("运行时间1不能为空");
                                }
                            }
                        } break;
                    case "3":
                        {
                            if (tLDcir.FocusedColumn.FieldName == "Value")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("采集时间1 empty");
                                }
                                else
                                {
                                    MessageBox.Show("采集时间1不能为空");
                                }
                            }
                        } break;
                }
            }
        }
        /// <summary>
        /// 时间为空校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimeSpan_Leave(object sender, EventArgs e)
        {
            if (tLDcir.FocusedNode["Value"] != null)
            {
                if (((TimeSpan)tLDcir.FocusedNode["Value"]) == new TimeSpan(0, 0, 0, 0, 0))
                {
                    tLDcir.SetRowCellValue(tLDcir.FocusedNode, tLDcir.FocusedColumn, null);
                }
            }
            else
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Please set 运行时间 or 采集时间");
                }
                else
                {
                    MessageBox.Show("工步必须设置运行时间或采集时间");
                }
                tLDcir.SetRowCellValue(tLDcir.FocusedNode, tLDcir.FocusedColumn, new TimeSpan(0, 0, 0, 30, 0));
            }
        }
        #endregion
        #region 国际化
        private void Dcir_Load(object sender, EventArgs e)
        {
            ResourceCulture.SetCurrentCulture(IndexPage.language);
            this.SetResourceCulture();
        }
        /// <summary>
        /// 为当前页面内所有控件设置文本语种
        /// </summary>
        private void SetResourceCulture()
        {
            this.rbtDouble.Text = ResourceCulture.GetString("Doublecurrent");
            this.rbtSingle.Text = ResourceCulture.GetString("Singlecurrent");
            this.tLIndex.Caption = ResourceCulture.GetString("Index");
            this.tLProperty.Caption = ResourceCulture.GetString("Property");
            this.tLValue.Caption = ResourceCulture.GetString("Value");
            this.tLUnit.Caption = ResourceCulture.GetString("Unit");
            this.tLVariate.Caption = ResourceCulture.GetString("Variate");
            this.gbxRecordCondition.Text = ResourceCulture.GetString("RecordConditionText");
            this.chkTimeSpanRC.Text = ResourceCulture.GetString("TimeSpanText");
            this.chkVSpanRC.Text = ResourceCulture.GetString("VolSpanText");
            this.chkASpanRC.Text = ResourceCulture.GetString("CurrSpanText");
            this.gbxSafeProtection.Text = ResourceCulture.GetString("SafeProText");
            this.chkVMinSP.Text = ResourceCulture.GetString("VolMinText");
            this.chkVMaxSP.Text = ResourceCulture.GetString("VolMaxText");
            this.chkAMinSP.Text = ResourceCulture.GetString("CurrMinText");
            this.chkAMaxSP.Text = ResourceCulture.GetString("CurrMaxText");
            this.chkTMaxSP.Text = ResourceCulture.GetString("TempMaxText");
            this.gbxDelayProct.Text = ResourceCulture.GetString("DelayProtect");
            this.chkStepDelayDP.Text = ResourceCulture.GetString("StepDelay");
            this.chkConDelayDP.Text = ResourceCulture.GetString("ContinueDelay");
            this.gbxHuaChengProct.Text = ResourceCulture.GetString("BFGSProtectCondition");
            this.chkVChangeRateHCP.Text = ResourceCulture.GetString("BFGSRate");
            this.lblDetectionTimeHCP.Text = ResourceCulture.GetString("DetectionTime");
            this.lblVValueHCP.Text = ResourceCulture.GetString("Vol");
            this.gbxPlatformV.Text = ResourceCulture.GetString("PlatVolt");
            this.chkPlatform1PV.Text = ResourceCulture.GetString("Plat") + " 1";
            this.chkPlatform2PV.Text = ResourceCulture.GetString("Plat") + " 2";
            this.chkPlatform3PV.Text = ResourceCulture.GetString("Plat") + " 3";
            this.gbxCustomerCurr.Text = ResourceCulture.GetString("CustomerCurr");
            this.chkCustCurr.Text = ResourceCulture.GetString("CusCur");
            this.lblCustCurrMin.Text = ResourceCulture.GetString("CusCurLower");
            this.lblCustCurrMax.Text = ResourceCulture.GetString("CustCurUpper");
            this.chkActivitiesCP.Text = ResourceCulture.GetString("Material");
            this.gbxBase.Text = ResourceCulture.GetString("BaseInfo");
            this.lblName.Text = ResourceCulture.GetString("Creator");
            this.lblNo.Text = ResourceCulture.GetString("PN");
            this.lblRemark.Text = ResourceCulture.GetString("Remarks");
            this.btnCancel.Text = ResourceCulture.GetString("LoginCancel");
            this.btnOk.Text = ResourceCulture.GetString("LoginOk");
        }
        #endregion
    }
}
